(function(){
	//用户中心菜单
	var setInterval001 = "";
	var _usernameWidth = '';

	function userSelectShow(){
		clearInterval(setInterval001);
		var _username = $("#selectNavUserName");
		_usernameWidth = _usernameWidth ? _usernameWidth : _username.width();
		_username.css({width: _usernameWidth + 1});
		_username.find("div").css({width: _username.width() - 24});
		//_username.css({width:_username.width()});
		_username.addClass("on");
		var _oLeft = _username.offset().left,
			_oTop = _username.offset().top;
		var _oHeight = _username.outerHeight();
		$("#userMenu_option").css({"left": _oLeft - (194 - _username.width()), "top": _oTop + _oHeight + 1});
		$("#userMenu_option").show();
	}

	function userSelectHide(){
		clearInterval(setInterval001);
		var _username = $("#selectNavUserName");
		setInterval001 = setInterval(function(){
			_username.removeClass("on");
			$("#userMenu_option").hide();
		}, 50);
	}

	function companyNav(){
		var hnav_html = '<ul> <li class="mobile"><i></i><a href="' + mainUrl('mobile_help') + '">手机版</a></li> <li class="refresh"><a href="' + mainUrl('/company/welcome?refreshtip=yes') + '">刷新职位</a><i></i></li> <li id="selectNavUserName" class="userName"><div><a href="' + mainUrl('/') + '"><span>' + company_logininfo_name + '</span><i></i></a></div></li> </ul>';
		var hnav_option_html = '<div id="userMenu_option" class="userMenu"> <ul> <li><a href="' + mainUrl('/company/welcome') + '"><span>账户中心</span></a></li> <li class="resume"><a href="' + mainUrl('/company/jobadmin') + '"><i></i><span>职位管理</span><b>管理</b></a></li> <li class="notice"><a href="' + mainUrl('/company/resume_message') + '"><i></i><span>收到简历</span><b>查看</b></a></li> <li><a href="' + mainUrl('/company/resume_favorite') + '"><span>人才库</span><b>查看</b></a></li> <li class="favorites"><a href="' + mainUrl('/company/interview_manage') + '"><i></i><span>面试管理</span><b>相看</b></a></li> <li class="set"><a href="' + mainUrl('/company/set_account') + '"><i></i><span>账号设置</span><b>设置</b></a></li> <li><a href="' + mainUrl('/company/logout') + '"><span>安全退出</span></a></li> </ul> </div>';
		$("#usernavcon").html(hnav_html);
		$("body").append(hnav_option_html);
		$("#selectNavUserName").hover(
			function(){
				userSelectShow();
			},
			function(){
				userSelectHide();
			}
		);
		$("#userMenu_option").hover(
			function(){
				userSelectShow();
			},
			function(){
				userSelectHide();
			}
		);
	}

	function personalNav(){
		var hnav_html = '<li class="mobile"><i></i><a href="' + mainUrl('mobile_help') + '">手机版</a></li><li class="refresh"><a href="' + mainUrl('/personal/resume_refresh') + '">刷新简历</a><i></i></li><li id="selectNavUserName" class="userName"><div><a href="' + mainUrl('/') + '"><span>' + personal_logininfo_name + '</span><i></i></a></div></li>';
		var hnav_option_html = '<div id="userMenu_option" class="userMenu"> <ul> <li><a href="' + mainUrl('/personal/welcome') + '"><span>账户中心</span></a></li> <li class="resume"><a href="' + mainUrl('/personal/resume_mange') + '"><i></i><span>我的简历</span><b>完善</b></a></li> <li class="notice"><a href="' + mainUrl('/personal/resume_mange') + '"><i></i><span>面试通知</span><b>查看</b></a></li> <li><a href="' + mainUrl('/personal/resume_send') + '"><span>申请的职位</span><b>查看</b></a></li> <li class="favorites"><a href="' + mainUrl('/personal/favorites') + '"><i></i><span>职位收藏夹</span><b>相看</b></a></li> <li class="set"><a href="' + mainUrl('/personal/set_account') + '"><i></i><span>账号设置</span><b>设置</b></a></li> <li><a  href="' + mainUrl('/personal/logout') + '"><span>安全退出</span></a></li> </ul> </div>';
		$("#usernavcon").html(hnav_html);
		$("body").append(hnav_option_html);
		$("#selectNavUserName").hover(
			function(){
				userSelectShow();
			},
			function(){
				userSelectHide();
			}
		);
		$("#userMenu_option").hover(
			function(){
				userSelectShow();
			},
			function(){
				userSelectHide();
			}
		);
	}

	function globalNav(){
		var hnav_html = '<li class="mobile"><i></i><a href="' + mainUrl('mobile_help') + '">手机版</a></li><li><a href="' + mainUrl('/personal/welcome') + '">个人登录</a></li><li><a href="' + mainUrl('/personal/register') + '">个人注册</a></li><li id="comloginnav" class="comloginnav"><div><a  href="' + mainUrl('/company/welcome') + '"><span>企业登录</span><i></i></a></div></li>';
		$("#usernavcon").html(hnav_html);
		var hnav_option_html = '<div id="comloginnav_option" class="comloginnavMenu"><ul><li><a href="' + mainUrl('/company/welcome') + '"><span>企业登录</span></a></li></li> <li><a  href="' + mainUrl('/company/register') + '"><span>企业注册</span></a></li> </ul></div>';
		$("body").append(hnav_option_html);
		//通用
		var setIntervalcomloginnav = "";

		function comLoginNavShow(){
			clearInterval(setIntervalcomloginnav);
			var _nav = $("#comloginnav");
			_nav.addClass("on");
			var _oLeft = _nav.offset().left,
				_oTop = _nav.offset().top;
			var _oHeight = _nav.outerHeight();
			$("#comloginnav_option").css({"left": _oLeft, "top": _oTop + _oHeight + 1});
			$("#comloginnav_option").show();
		}

		function comLoginNavHide(){
			clearInterval(setIntervalcomloginnav);
			var _nav = $("#comloginnav");
			setIntervalcomloginnav = setInterval(function(){
				_nav.removeClass("on");
				$("#comloginnav_option").hide();
			}, 50);
		}

		$("#comloginnav").hover(
			function(){
				comLoginNavShow();
			},
			function(){
				comLoginNavHide();
			}
		);
		$("#comloginnav_option").hover(
			function(){
				comLoginNavShow();
			},
			function(){
				comLoginNavHide();
			}
		);
	}

	if(company_logininfo_name != ''){//企业登录
		companyNav();
	}else if(personal_logininfo_name != ''){//个人登录
		personalNav();
	}else{//没有登录
		globalNav();
	}


	//分站功能 判断是不是添加分站
	if($('#station').length > 0){
		$("#changeregion a").hover(function(){
			var station = $("#station");
			station.css({'left': $(this).offset().left, 'top': $(this).offset().top + $(this).height()}).show();
			station.hover(function(){ $(this).show(); }, function(){ $(this).hide(); });
		}, function(){
			$("#station").hide();
		});
	}
	//检查用户是不是登录
	if(personal_logininfo_name != '' && personal_logininfo_name != 'undefined'){
		//检查个人的cookie是不是存在
		if(getCookie('personal_cookie') == null || getCookie('personal_cookie') == ''){
			setPersonalCookie();
		}
	}

	/**
	 * 设置个人登录刷新
	 */
	function setPersonalCookie(){
		$.get("personal/set_personal_cookie", function(data){
			if(data.status == '1'){
				setCookie('personal_cookie', 1,  1 / 24);
				layer.open({
					type: 1,
					title: "温馨提示",
					move: false,
					skin: 'layui-layer-rim', //加上边框
					area: ['480px', '300px'], //宽高
					content: '<div class="rightMain" style="padding:0px; width:450px;"><div class="refresh">' +
					'<div class="authentication">' +
					'<span class="planIco">今天还没刷新简历，刷新提高简历曝光率!<br>刷新前请确认以下信息准确完整：</span>' +
					'<span class="planTip">手机号码：' + data.info.mobile + '</span>' +
					'<span class="planTip">求职状态：' + data.info.job_status + ' <a href="/personal/resume_refresh">修改</a></span>' +
					'<span class="planTip">您的简历最近一次更新日期是：' + data.info.updatetime + '</span>' +
					'<span class="planAgain"><a onclick="cookieRefresh()">刷新简历</a></span>' +
					'<span class="planAgain planCancel"><a href="javascript:layer.closeAll()">以后再说</a></span>' +
					'</div>' +
					'</div></div>'
				});
			}else if(data.status == '2'){
				setCookie('personal_cookie', 1,  1 / 24);
			}
		});
	}

})(jQuery);

/**
 * 直接刷新简历
 */
function cookieRefresh(){
	$.get("personal/cookie_resume_refresh", function(data){
		if(data.status == '1'){
			layer.msg(data.msg, {time: 1500});
			setTimeout(function(){
				layer.closeAll();
			}, 1500);
		}else if(data.status == '2'){
			layer.msg(data.msg, {time: 1500});
			setTimeout(function(){
				layer.closeAll();
			}, 1500);
		}
	});
}
